package com.itchen.hospital.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itchen.hospital.exception.CustomException;
import com.itchen.hospital.mapper.SchedulingMapper;
import com.itchen.hospital.pojo.Scheduling;
import com.itchen.hospital.pojo.Params;
import com.itchen.hospital.service.SchedulingService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class SchedulingServiceImpl implements SchedulingService {


    private final SchedulingMapper schedulingMapper;

    /**
     * 查询所有
     * @return
     */
    @Override
    public List<Scheduling> getAll() {
        return schedulingMapper.getAll();
    }

    //条件查询
    @Override
    public PageInfo<Scheduling> search(Params params) {
        //处理分页
        PageHelper.startPage(params.getPageNum(), params.getPageSize());
        List<Scheduling> list = schedulingMapper.findBySearch(params);
        return PageInfo.of(list);
    }

    //添加
    @Override
    public void add(Scheduling scheduling) {
        schedulingMapper.add(scheduling);
    }

    //修改
    @Override
    public void update(Scheduling scheduling) {
        schedulingMapper.update(scheduling);
    }

    //根据id查询
    @Override
    public Scheduling findById(String id) {
        Scheduling scheduling = schedulingMapper.findById(id);
        return scheduling;
    }

    //删除
    @Override
    public void delete(String id) {
        schedulingMapper.delete(id);
    }

    //批量删除
    @Override
    public void batchDelete(List<Scheduling> schedulings) {
//        schedulings.forEach(scheduling -> {
//            schedulingMapper.delete(scheduling.getAccount());
//        });
    }
}
